<?php namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Services\ItemService;
use App\Models\Item;
use App\Models\Catalog;
use App\Models\Area;

class ItemController extends Controller
{

    public function getIndex(ItemService $itemService, Request $request)
    {
        return view('admin.item.items', [
            'types' => Item::$_typeName,
            'p_catalogs' => Catalog::where(['p_id' => 0, 'level' => 1])->get(),
            'catalogs' => Catalog::where(['p_id' => $request->input('p_catalog_id'), 'level' => 2])->get(),
            'provinces' => Area::where(['p_id' => 0, 'level' => 1])->get(),
            'cities' => Area::where(['p_id' => $request->input('province_id'), 'level' => 2])->get(),
            'districts' => Area::where(['p_id' => $request->input('city_id'), 'level' => 3])->get(),
            'items' => $itemService->getList($request),
            'request' => $request,
        ]);
    }

    public function getInfo($id)
    {
        return view('admin.item.item', [
            'item' => Item::find($id),
        ]);
    }

    public function getDelete($id, ItemService $itemService)
    {
        $itemService->delete($id);
        return $this->bSuccess('删除成功', false);
    }
}